/**
 * @author		Ben Layet
 * @version 	0.1
 * @date		5 Sep 2008
 * @copyright 	� Canon Europa N. V. 2004
 */
package org.learnaholic.application.test.ui;

import java.awt.Color;
import java.awt.Dimension;

import javax.swing.BoxLayout;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import org.learnaholic.application.model.TestDialogElementDefinition;
import org.learnaholic.application.ui.UiConstants;

/**
 * 
 */
public abstract class AbstractTestInput extends AbstractPanelTestComponent implements TestComponent
{
	private final JLabel nameLbl;
	private final JPanel questionComponent = new JPanel();
	private final JComponent	 inputComponent;
	
	/**
	 * 
	 */
	public AbstractTestInput(JComponent inputComponent, TestDialogElementDefinition definition)
	{
		super(definition);
		questionComponent.setOpaque(false);
		questionComponent.setLayout(new BoxLayout(questionComponent, BoxLayout.Y_AXIS));
		add(questionComponent);
		nameLbl = new JLabel(definition.getName());
		nameLbl.setFont(UiConstants.small_font);
		questionComponent.add(nameLbl);
		questionComponent.add(inputComponent);
		this.inputComponent = inputComponent;
		inputComponent.setFont(UiConstants.medium_font);
		inputComponent.setPreferredSize(new Dimension(500,30));
	}
	
	
	/**
	 * @param answerMode
	 */
	public void setAnswerMode(boolean answerMode)
	{
		super.setAnswerMode(answerMode);
		
		if(answerMode)
		{
			remove(questionComponent);
		}
		else
		{
			add(questionComponent);
		}
	}

	protected JPanel getQuestionComponent()
	{
		return questionComponent;
	}
	
	/**
	 * @return
	 */
	public JComponent getInputComponent()
	{
		return  inputComponent;
	}
	
	public void setForeground(Color color)
	{
		if(null != nameLbl)
		{
			nameLbl.setForeground(color);
		}
		super.setForeground(color);
	}
	
	
}
